<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"   lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>接入系统管理</title>
        <link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.5.4.5/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.5.4.5/themes/icon.css">
        <script src="/js/jquery-easyui-1.5.4.5/jquery.min.js"></script>
        <script src="/js/jquery-easyui-1.5.4.5/jquery.easyui.min.js"></script>
    </head>

    <body>
	    <table class="easyui-datagrid" title="业务系统管理" style="width:90%;height:500px" id="table-grid"
			data-options="singleSelect:true,collapsible:false,url:'/tradeSys/list',method:'get',toolbar:toolbar,pagination:true,pageSize:20">
		<thead>
			<tr>
				<th data-options="field:'sysId',checkbox:true"></th>
				<th data-options="field:'sysName',width:100,editor:{
				type:'text'
				}">系统名称</th>
				<th data-options="field:'sysUrl',width:400,align:'right',editor:{
				type:'text'
				}">访问地址</th>
				<!-- <th data-options="field:'sysIcon',width:80,align:'right'">系统图标</th> -->
				<th data-options="field:'sysStatus',width:250,editor:{
				type:'combobox',
				options:{
							valueField:'sysStatus',
							textField:'statusName',
							data:[{'sysStatus':'1','statusName':'有效'},{'sysStatus':'0','statusName':'无效'}],
							required:true
						}
			},formatter: function(value,row,index){
				if(value == '0') return '无效';
				if(value == '1') return '有效';
			}">系统状态</th>
				<th data-options="field:'sysLevel',width:60,align:'center',editor:{
				type:'combobox',
				options:{
							valueField:'sysLevel',
							textField:'levelName',
							data:[{'sysLevel':'1','levelName':'1级系统'}],
							required:true
						}
				},formatter: function(value,row,index){
				if(value == '1') return '1级系统';
			}">系统级别</th>
				<th data-options="field:'AccessMode',width:60,align:'center',editor:{
				type:'combobox',
				options:{
							valueField:'AccessMode',
							textField:'modeName',
							data:[{'AccessMode':'1','modeName':'菜单接入'},{'AccessMode':'2','modeName':'系统接入'}],
							required:true
						}
				},formatter: function(value,row,index){
				if(value == '1') return '菜单接入';
				if(value == '2') return '系统接入';
			}">集成方式</th>
			</tr>
		</thead>
	</table>

  <script src="/js/dataGrid.js"></script>
  <script type="text/javascript">		
	//dataGrid工具栏
	var toolbar = [{
				text:'新增',
				iconCls:'icon-add',
				handler:function(){
					var tt = $('#table-grid');
					tt.datagrid("appendRow",{sysId:"",sysName:"",sysUrl:"", sysIcon:"", sysStatus:"1",sysLevel:"1",AccessMode:"1"});
					//var row = tt.datagrid("getFooterRows") ;
					//var rowId = tt.datagrid('getRowIndex',row);
					//if(rowId >=0){
					//	tt.datagrid('selectRow',rowId+1);
					//	tt.datagrid('beginEdit',rowId+1);
					//	 $("div.datagrid-toolbar [id ='save']").eq(0).show(); 
					//	 $("div.datagrid-toolbar [id ='cancel']").eq(0).show(); 
					//}
				}
			},{
				text:'编辑',
				iconCls:'icon-edit',
				handler:function(){
					var tt = $('#table-grid');
					var rowId = getRowIndex(tt);
					if(rowId >=0){
						tt.datagrid('beginEdit',rowId);
						 $("div.datagrid-toolbar [id ='save']").eq(0).show(); 
						 $("div.datagrid-toolbar [id ='cancel']").eq(0).show(); 
					}
				}
			},{
				text:'删除',
				iconCls:'icon-remove',
				handler:function(){
							var tt = $('#table-grid');
							var row=tt.datagrid('getSelected');
							if(row == null){
								$.messager.alert('Warning','请选择要删除的行！');
							}
					$.messager.confirm('提示','您确定要删除吗？',function (r){
						if(r){
							$.ajax({
								   type: "POST",
								   dataType:"json",
								   url: "/tradeSys/del",
								   data: {sysId:row.sysId},
								   success: function(msg){
								     if(msg){
								    	 $.messager.alert('Warning',msg.retMsg);
								    	 $('#table-grid').datagrid('reload');
								     }
								   }
								});
						}
					});
				}
			},'-',{
				id:'save',
				text:'保存',
				iconCls:'icon-save',
				handler:function(){
					var tt = $('#table-grid');
					var rowId = getRowIndex(tt);
					var row=tt.datagrid('getSelected');
					tt.datagrid('endEdit',rowId);
					$.ajax({
						   type: "POST",
						   dataType:"json",
						   url: "/tradeSys/save",
						   data: {sysId:row.sysId,sysName:row.sysName,sysUrl:row.sysUrl, sysIcon:row.sysIcon,
							   sysStatus:row.sysStatus,sysLevel:row.sysLevel,AccessMode:row.AccessMode},
						   success: function(msg){
						     if(msg){
						    	 $.messager.alert('Warning',msg.retMsg);
								 $("div.datagrid-toolbar [id ='save']").eq(0).hide(); 
								 $("div.datagrid-toolbar [id ='cancel']").eq(0).hide(); 
						     }
						   }
						});
				}
			},{
				id:'cancel',
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					var tt = $('#table-grid');
					var rowId = getRowIndex(tt);
					var row=tt.datagrid('getSelected');
					tt.datagrid('cancelEdit',rowId);
					$("div.datagrid-toolbar [id ='save']").eq(0).hide(); 
					$("div.datagrid-toolbar [id ='cancel']").eq(0).hide(); 
					if(row.sysId == null){
						tt.datagrid("deleteRow",rowId);
					}
				}
			}];
		$(function(){
			$('#table-grid').datagrid({				
				onBeforeLoad:function(param){
					 $("div.datagrid-toolbar [id ='save']").eq(0).hide(); 
					 $("div.datagrid-toolbar [id ='cancel']").eq(0).hide(); 
				},
				onBeforeEdit:function(index,row){
					row.editing = true;
				},
				onAfterEdit:function(index,row){
					row.editing = false;
				},
				onCancelEdit:function(index,row){
					row.editing = false;
				}				
			});
		});
	</script>      
    </body>
</html>
